<template>
	<div class="port-page">
		<div>
			<el-collapse v-model="activeNames" class="xiala">
				<el-collapse-item title=" ★  教材类" name="1">
					<div style="border: 1px #CCCCCC;">
						<div class="jclt">预约阶段</div>
						<div class="jclt">试听阶段</div>
						<div class="jclt">催单阶段</div>
						<div class="jclt">其他资料</div>
					</div>
				</el-collapse-item>
			</el-collapse>
			<div class="zhongxin">
				<div style="height: 50px; line-height: 50px; padding-left: 20px; font-size: 20px; border-bottom: 1px solid #E8EDF0;">
					新闻资料--中心
				</div>
				<div style="height: 60px; line-height: 60px; padding-left: 20px;  border-bottom: 1px solid #E8EDF0;">
					<router-link to="/home">
						<el-button type="warning" size="small" style='margin-right: 10px;' icon="el-icon-menu">首页</el-button>
					</router-link>
					<el-button type="warning" size="small" style='margin-right: 10px;' @click="componentsShow('add')">新增</el-button>
				</div>
				<div>
					<ul>
						<li style="height: 150px; border: 1px solid #E8EDF0; overflow: hidden;" v-for="i in dataList">
							<div style="float: left;width: 10%;height: 100%; border-right: 1px solid #E8EDF0; "><img :src="i.fm" /></div>
							<div style="float: left;width: 75%;height: 100%; border-right: 1px solid #E8EDF0;">
								<p style="height: 33%; line-height: 50px; font-size: 24px; padding-left: 20px;">{{i.title}}</p>
								<p style="height: 33%; line-height: 50px; font-size: 14px; padding-left: 20px;">内容：{{i.note}}</p>
								<p style="height: 33%; line-height: 50px; text-align: right; font-size: 14px; padding-right: 20px;">时间 ：{{i.sj}}&nbsp;&nbsp;浏览次数：{{i.cns}}&nbsp;&nbsp;收藏次数：{{i.sccns}}</p>
							</div>
							<div style="float: left;width: 15%;height: 100%;  text-align:center;line-height: 150px;">
								<router-link :to="{path:'/Marketing/xwzledit',query: {iid:i.id}}">
									<el-button type="" size="mini" style='margin-right: 10px;'>预览</el-button>
								</router-link>
								<el-button type="" size="mini">编辑</el-button>
								<el-button type="" size="mini" style='margin-right: 10px;' @click="centerDialogVisible = true">分享</el-button>
							</div>
						</li>
					</ul>
				</div>
			</div>
		</div>
		<el-dialog title="分享设置" :visible.sync="centerDialogVisible" width="500px">
			<el-form label-width="150px" class="form">
				<el-form-item label="分享朋友圈标题" >
					<el-input v-model="pyqtt" style='width: 250px;' placeholder="" icon="add"  ></el-input>
				</el-form-item>
				<el-form-item label="分享朋友圈内容" >
					<el-input v-model="pyqnr" style='width: 250px;' placeholder="" icon="add"  ></el-input>
				</el-form-item>
				<el-form-item label="分享朋友圈头像" >
					<el-input v-model="pyqimg" style='width: 250px;' placeholder="" icon="add"  ></el-input>
				</el-form-item>
			</el-form>
			<span slot="footer" class="dialog-footer">
			    <el-button @click="centerDialogVisible = false">取 消</el-button>
			    <el-button type="primary" @click="centerDialogVisible = false">确 定</el-button>
			</span>
		</el-dialog>
		<!-- 动画加载 -->
		<LoadingComponent v-show="isLoading"></LoadingComponent>
		<AddComponent v-if="portComponents.add.toggle" @close="componentsHide"></AddComponent>
		<!-- 子路由显示区域 -->
		<router-view class="port-view"></router-view>
	</div>
</template>
<script>
	import { mapState } from 'vuex'
	import LoadingComponent from 'components/loading'
	import AddComponent from './add2'

	import qs from 'qs'
	export default {
		components: {
			LoadingComponent,
			AddComponent
		},
		data() {
			return {
				pyqtt:'',
				pyqnr:'',
				pyqimg:'',
				centerDialogVisible:false,
				activeNames: '',
				vkeyword: '',
				dataList: [],
				portComponents: {
					add: {
						type: 'add',
						toggle: false,
						params: '',
						data: {}
					},
				},
				layout: 'total, sizes, prev, pager, next, jumper', //组件布局
				pageindex: this.$store.state.pageindex, //当前分页页码
				pagesizes: this.$store.state.pagesizes, //显示个数的选择器选项
				pagesize: this.$store.state.pagesize, //每页显示条目数
				total: 0, //总条数
			}
		},
		created() {
			//加载页面时调用
			this.$store.dispatch('changeTitle', '新闻资料'); //修改title
			this.$store.dispatch('changeRouterIndex', '/Marketing/xwzl'); //修改路由
			this.search(); //分页获取默认数据
			// this.getcomlist(); //加载下拉列表
			this.isLoading = true; //动画开始
		},
		mounted() {
			//加载完成之后event
			this.isLoading = false; //动画结束
		},
		methods: {
			search() {
				//查询搜索触发事件
				var logininfo = JSON.parse(localStorage.logininfo);
				var params3 = qs.stringify({
					keyword: this.vkeyword, // 关键字
					yhid: logininfo.id,
					xxid: logininfo.xxid,
					pageindex: this.pageindex,
					pagesize: this.pagesize
				});
				this.searchLoading = true;
				this.axios.post(this.$store.state.api + 'yxxw/list', params3)
					.then(res => {
						console.log(res)
						let data = res.data.data;
						let list = data.list;
						this.total = data.totalPage;
						this.dataList = list;
						this.searchLoading = false;
					}).catch(res => {
						console.log(res)
						this.searchLoading = false;
					})
			},
			handleSizeChange(val) { //每页显示条数触发事件
				this.pagesize = val;
				this.pageindex = 1;
				this.search();
			},
			handleCurrentChange(val) { //分页触发事件
				this.search();
			},
			/* 组件的弹框  */
			componentsShow(type, data) { //显示组件
				console.log(type, data)
				for(let i in this.portComponents) {
					if(type == this.portComponents[i].type) {
						this.portComponents[i].toggle = true;
						this.portComponents[i].params = data;
						if(this.portComponents[i].data.type == 'single') {
							this.portComponents[i].data.index = data.row.id
						} else if(this.portComponents[i].data.type == 'multiple') {
							this.portComponents[i].data.index = this.multipleDelNum;
						} else {
							return;
						}
						return;
					}
				}
			},
			componentsHide(setting) { //关闭组件
				console.log(setting)
				this.search(); //分页获取默认数据
				for(let i in this.portComponents) {
					if(setting.type == this.portComponents[i].type) {
						this.portComponents[i].toggle = false;
						if(!setting.cancel) {
							this.search();
						}
						return;
					}
				}
			}
		},
		computed: {
			...mapState([
				'api' //域名
			]),
			multipleDeleteDisabled() {
				console.log(this.multipleDelNum)
				if(this.multipleDelNum) {
					return false;
				} else {
					return true
				}
			}
		}
	}
</script>

<style lang="less" scoped>
	.port-page {
		font-size: 12px;
		margin-top: 20px;
		background: white;
		padding-top: 20px;
		padding-bottom: 20px;
		overflow: hidden;
		.xiala {
			float: left;
			border: 1px solid #E8EDF0;
			width: 15%;
			margin-left: 10px;
		}
		.jclt {
			width: 100%;
			height: 40px;
			float: left;
			font-size: 16px;
			text-align: center;
			line-height: 40px;
			border-top: 1px solid #E8EDF0;
			cursor: pointer;
		}
		.zhongxin {
			float: left;
			margin-left: 20px;
			width: 80%;
			min-height: 600px;
			border: 1px solid #E8EDF0;
		}
	}
</style>